name: Push to template repository

on:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Get npm cache directory
        id: npm-cache
        run: |
          echo "dir=$(npm config get cache)" >> "$GITHUB_OUTPUT"
      - uses: actions/cache@v3
        with:
          path: ${{ steps.npm-cache.outputs.dir }}
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "lts/*"
      - name: Install dependencies
        run: npm ci
      - name: Build
        run: npm run build
      - name: Pushes to another repository
        uses: cpina/github-action-push-to-another-repository@main
        env:
          API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
        with:
          source-directory: "dist"
          destination-github-username: "h5bp"
          destination-repository-name: "html5-boilerplate-template"
          user-name: "roblarsen"
          user-email: rob@htmlcssjavascript.com
          commit-message: "The latest and greatest from HTML5 Boilerplate"
